<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-19 下午3:34
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}

include_once 'forum.php';
class cloud_api {
    function common() {
        global $_G;

        $_FILES['Filedata']['name'] = addslashes(diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8'));
        $_FILES['Filedata']['type'] = $_GET['filetype'];
        //初始化上传的文件信息
        $file = plugin_cloud::update_init($_FILES['Filedata'], 'product');

        //保存到指定的文件夹中
        plugin_cloud::saveUpload($file);
        //将图片插入到数据库中，并返回id
        $fileOtherName =explode('.',censor($file['name']));

        $isDisplay = C::t('#cloud#cloud_product_photo')->search_display($_GET['cpid'],$_GET['display']);
        if(!empty($isDisplay)){
            C::t('#cloud#cloud_product_photo')->delete_by_id($isDisplay['cppid']);
        }

            if($_GET['display'] == 1){
                // 更新产品图片URl
                C::t('#cloud#cloud_product')->update($_GET['cpid'],$data=array('picurl'=>$file['attachment']));
            }else{
                $insert = array(
                    'cpid' => $_GET['cpid'],
                    'name' => empty($_GET['name'])? $fileOtherName[0]:$_GET['name'],
                    'display' => $_GET['display'],
                    'url' => $file['attachment'],
                    'lasttime' => TIMESTAMP,
                );
                $caaid = C::t('#cloud#cloud_product_photo')->insert($insert);
            }

        plugin_cloud::uploadMsg(0, $caaid);
    }

    function output() { }


}
?>

